import functools
import collections


class Solution(object):
    def getMaxGridHappiness(self, m, n, introvertsCount, extrovertsCount):
        @functools.cache
        def judge(val):
            now_ans = 0
            last = 0
            in_count = 0
            ex_count = 0
            for i in range(n):
                now_val = val % 3
                if now_val == 0:
                    last = 0
                if now_val == 1:
                    if last == 0:
                        now_ans += 120
                    if last == 1:
                        now_ans += 60
                    if last == 2:
                        now_ans += 110
                    last = 1
                    in_count += 1
                if now_val == 2:
                    if last == 0:
                        now_ans += 40
                    if last == 1:
                        now_ans += 30
                    if last == 2:
                        now_ans += 80
                    last = 2
                    ex_count += 1
                val = val // 3
            return now_ans, in_count, ex_count

        @functools.cache
        def cal(last_val, val):
            last_ans, _, _ = judge(last_val)
            if last_ans == -1:
                return -1
            now_ans, _, _ = judge(val)
            if now_ans == -1:
                return -1
            t_ans = now_ans
            for i in range(n):
                last_wei = last_val % 3
                now_wei = val % 3
                if last_wei == 1:
                    if now_wei == 1:
                        t_ans -= 60
                    if now_wei == 2:
                        t_ans -= 10
                if last_wei == 2:
                    if now_wei == 1:
                        t_ans -= 10
                    if now_wei == 2:
                        t_ans += 40
                last_val = last_val // 3
                val = val // 3
            return t_ans
        max_val = 0
        st = {(0, 0, 0): 0}
        for i in range(m):
            next_st = collections.defaultdict(int)
            for last_node in st:
                last_val, last_in, last_ex = last_node[0], last_node[1], last_node[2]
                for val in range(3 ** n):
                    now_ans = cal(last_val, val)
                    _, now_in, now_ex = judge(val)
                    now_ans += st[last_node]
                    now_in += last_in
                    now_ex += last_ex
                    if now_in == introvertsCount and now_ex == extrovertsCount:
                        max_val = max(max_val, now_ans)
                    else:
                        if now_in <= introvertsCount and now_ex <= extrovertsCount:
                            next_st[(val, now_in, now_ex)] = max(now_ans, next_st[(val, now_in, now_ex)])
            st = next_st
        for node in st:
            if node[1] <= introvertsCount and node[2] <= extrovertsCount:
                max_val = max(max_val, st[node])
        return max_val


data = Solution()
m = 3
n = 3
introvertsCount = 3
extrovertsCount = 1
print(data.getMaxGridHappiness(m, n, introvertsCount, extrovertsCount))
